package com.tb.dubbo_service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tb.dubbo.IgoodsService2;
import com.tb.mapper.GoodsMapper;
import com.tb.pojo.Goods;
import com.tb.utils.Msg;
import com.tb.utils.ReturnList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class GoodsServiceImpl2 implements IgoodsService2 {
    @Autowired
    private GoodsMapper goodsMapper;
    /*商品列表并排序*/
    @Override
    public Msg getAllGoods(Map<String,Object> map) {
        //总条目数
        long count=goodsMapper.selectGoodsBysold(map).size();
        //使用PageHelper实现分页，页码数，每页显示的最大条目数
        int page=(Integer) map.get("page");
        int rows=(Integer) map.get("rows");
        PageHelper.startPage(page,rows);
        List<Goods> list=goodsMapper.selectGoodsBysold(map);

        PageInfo<Goods> info=new PageInfo<>(list);
        ReturnList returnList = ReturnList.get(count, info.getList());

        return Msg.success(returnList);
    }
}

